package com.NetSunWeiQin.chapter11.flight;

import java.rmi.*;
import java.rmi.server.*;
import java.util.*;

public class FlightFactoryImpl extends UnicastRemoteObject implements FlightFactory {


    private Hashtable<String, Flight> flights;  //缓存flight 对象

    FlightFactoryImpl() throws RemoteException {
        flights = new Hashtable<>();
    }

    public Flight getFlight(String flightNumber) throws RemoteException {
        Flight flight = flights.get(flightNumber);
        if (flight != null) return flight;

        flight = new FlightImpl(flightNumber, null, null, null, null);
        flights.put(flightNumber, flight);
        return flight;
    }
}

